// 声明一个对象
const banji = {
  name: '一班',
  stus: ['luck', 'lucy', 'jack'],
  // !加上iterator()
  // Result of the Symbol.iterator method is not an object
  [Symbol.iterator]() {

    // 索引
    let index = 0;
    let _this = this;

    // undefined is not a function
    return {
      // Iterator result undefined is not an object
      next: function () {
        if (index < _this.stus.length) {
          const result = { value: _this.stus[index], done: false };
          // 下标自增
          index++;
          // 返回结果
          return result;
        } else {
          return { value: undefined, done: true };
        }
      }
    };
  }
};

// 遍历对象 for...of 每次返回的结果是这个数组里面的成员
for (let v of banji) {
  // console.log(v); //banji is not iterable
  //luck
  //lucy
  //jack
  console.log(v);
}